home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / include / object.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  14.7 KB  |  631 lines

  1. #ifndef _OBJECT_H_
  2. #define _OBJECT_H_
  3. /*
  4.  *   $RCSfile: object.h,v $  
  5.  *   $Revision: 1.1.1.1 $  
  6.  *   $Date: 1996/05/04 21:55:08 $      
  7.  */ 
  8. #ifndef __OBJECT_H__
  9. #define __OBJECT_H__
  10.  
  11. /**********************************************************************
  12. * EXODUS Database Toolkit Software
  13. * Copyright (c) 1991 Computer Sciences Department, University of
  14. *                    Wisconsin -- Madison
  15. * All Rights Reserved.
  16. *
  17. * Permission to use, copy, modify and distribute this software and its
  18. * documentation is hereby granted, provided that both the copyright
  19. * notice and this permission notice appear in all copies of the
  20. * software, derivative works or modified versions, and any portions
  21. * thereof, and that both notices appear in supporting documentation.
  22. *
  23. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  24. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  25. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  26. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  27. *
  28. * The EXODUS Project Group requests users of this software to return 
  29. * any improvements or extensions that they make to:
  30. *
  31. *   EXODUS Project Group 
  32. *     c/o David J. DeWitt and Michael J. Carey
  33. *   Computer Sciences Department
  34. *   University of Wisconsin -- Madison
  35. *   Madison, WI 53706
  36. *
  37. *     or exodus@cs.wisc.edu
  38. *
  39. * In addition, the EXODUS Project Group requests that users grant the 
  40. * Computer Sciences Department rights to redistribute these changes.
  41. **********************************************************************/
  42.  
  43. /* BEGIN visible to user */
  44.  
  45. /*
  46.  *    object.h
  47.  *
  48.  *        defines, typedefs, etc. used by object-level routines and
  49.  *        clients of the storage manager.
  50.  */
  51.  
  52. /*
  53.  *    define the size of slotted pages
  54.  */
  55. #define SLOTTED_PAGE2SIZE    MIN_PAGE2SIZE
  56. #define SLOTTED_PAGESIZE    (1 << SLOTTED_PAGE2SIZE)
  57.  
  58.  
  59. /*
  60.  *    define the sizes of large object pages
  61.  */
  62. #define LG_PAGE2SIZE    MIN_PAGE2SIZE
  63. #define LG_PAGESIZE        (1 << LG_PAGE2SIZE)
  64. #if    (MIN_PAGE2SIZE == 12)
  65. #    define LGDATA_PAGE2SIZE    (MIN_PAGE2SIZE+1) /* double lg obj pages */
  66. #else
  67. #    define LGDATA_PAGE2SIZE    (MIN_PAGE2SIZE)   /* large obj pages == others */
  68. #endif
  69. #define LGDATA_PAGESIZE    (1 << LGDATA_PAGE2SIZE)
  70. /*#define LGDATA_USABLESIZE is defined below */
  71.  
  72.  
  73. /*
  74.  *    define the sizes of btree pages
  75.  */
  76. #define BTREE_PAGE2SIZE        MIN_PAGE2SIZE
  77. #define BTREE_PAGESIZE        (1 << BTREE_PAGE2SIZE)
  78. #define INDEXDESC_PAGE2SIZE    MIN_PAGE2SIZE
  79. #define INDEXDESC_PAGESIZE    (1 << INDEXDESC_PAGE2SIZE)
  80.  
  81. /*
  82.  *    define the number of uniques allocated when page is created
  83.  *    (100 per every 4K of pagesize)
  84.  */
  85. #if SLOTTED_PAGE2SIZE < 12
  86. #define UNIQUE_ALLOC_COUNT    (100)
  87. #else
  88. #define UNIQUE_ALLOC_COUNT    (100+100*(SLOTTED_PAGE2SIZE-12))
  89. #endif
  90.  
  91.     
  92. /*
  93.  *    Typedef for object addresses.
  94.  */
  95. typedef struct OBJADDR {
  96.  
  97.     SHORTPID    page;            /* the page address of the object's header    */
  98.     SLOTINDEX    slot;            /* slot number of the object                */
  99.     VOLID        volid;            /* the id of the volume                        */
  100.     UNIQUE        unique;            /* unique number of the object                */
  101.  
  102. } OBJADDR;
  103.  
  104.  
  105. /*
  106.  * Typedef for object ids.
  107.  */
  108. typedef struct OID {
  109.  
  110.     OBJADDR  diskAddr;            /* the object's disk address    */
  111.  
  112. } OID;
  113.  
  114.  
  115. /* END visible to user */
  116.  
  117.  
  118. /*
  119.  *    Typedef for object ids.
  120.  */
  121. typedef struct INTOID {
  122.  
  123.     OBJADDR        diskAddr;        /* the object's disk address    */
  124.     SHORTPID    fid;            /* the object's file id            */
  125.  
  126. } INTOID;
  127.  
  128.  
  129. /* BEGIN visible to user */
  130.  
  131. /*
  132.  *    Defines for near in CreateObject call.
  133.  */
  134. #define NEAR_OBJ              1
  135. #define NEAR_FIRST            2
  136. #define NEAR_LAST            3
  137. #define NEAR_DISTINGUISHED    4    /* not used */
  138. /* for backward compatibility */
  139. #define NEAR_FIRST_PHYSICAL    NEAR_FIRST
  140. #define NEAR_LAST_PHYSICAL    NEAR_LAST    
  141. #define NEAR_FIRST_LOGICAL    NEAR_FIRST
  142. #define NEAR_LAST_LOGICAL    NEAR_LAST
  143.  
  144.  
  145. /*
  146.  *    Typedef for generic object headers as viewed by clients of the storage manager.
  147.  *    Note that the fields must match the initial fields of SMALLOBJHDR 
  148.  *    and LARGEOBJHDR (all the same for now).
  149.  */
  150. typedef struct OBJHDR {
  151.  
  152.     TWO            properties;        /* the properties bit vector    */
  153.     TWO            tag;            /* the object's tag                */
  154.     FOUR        size;            /* the object's data size        */
  155.  
  156.     /* MUST MAINTAIN 8-byte ALIGNMENT HERE: if you change this 
  157.      * the size of the OBJHDR, you might have to add a filler
  158.      * to maintain 8-byte alignment e.g.
  159.         FOUR        filler;        
  160.      */
  161.  
  162. #if OBJECT_MAGIC IS_ENABLED
  163.     MAGIC        magic;
  164. #if (ALIGNON == 8)
  165.     FOUR        filler;        
  166.     /* no alignment needed */
  167. #elif (ALIGNON == 4)
  168.     /* no alignment needed */
  169. #else
  170.     not implemented
  171. #endif
  172. #endif OBJECT_MAGIC IS_ENABLED
  173.  
  174.  
  175. } OBJHDR;
  176.  
  177.  
  178. #define OBJECT_HDR_MAGIC        0x8AC429DA
  179.  
  180.  
  181. /* END visible to user */
  182.  
  183. /* BEGIN visible to E */
  184.  
  185. /* 
  186.  *    Typedef for small objects.
  187.  */
  188. typedef struct SMALLOBJ {
  189.  
  190.     OBJHDR    objectHdr;                /* the object's header    */
  191.     char    data[ALIGNSIZE(sizeof(SHORTPID))];     /* data area */
  192.     /*
  193.      *    Making the data array larger is required to enforce the
  194.      *    requirement that small objects at least be large enough to
  195.      *    hold a large object header (LARGEOBJHDR).  
  196.      */
  197. } SMALLOBJ;
  198.  
  199.  
  200. /* 
  201.  *    Typedef for generic object.
  202.  *    This is used to determine what type of object we are dealing with.
  203.  *    Once the object type is determined, then either the SMALLOBJ or
  204.  *    LARGEOBJ typedef is used, depending, of course, on whether we are
  205.  *    dealing with a large or small object.  For now the basic structure
  206.  *    of an object is that of a small object.  In case of a large object
  207.  *    the data area is used to hold control information.
  208.  */
  209. typedef SMALLOBJ OBJECT;
  210.  
  211. /* END visible to E */
  212.  
  213. /*
  214.  * ------- LARGE OBJECT DEFINITION STUFF ----------
  215.  */
  216.  
  217. /*
  218.  *    Format of (count, page-pointer) pair for internal nodes.
  219.  */
  220. typedef struct LGSLOT {
  221.  
  222.     PID     pid;        /* pointer to root of child                    */
  223.     BOOL    shared;        /* true if page is shared by another version*/
  224.     FOUR    count;        /* child's byte count                        */
  225.  
  226. } LGSLOT;
  227.  
  228.  
  229. /*
  230.  *    Lower the fanout of lg obj btree nodes by defining LGTESTING
  231.  */
  232. #define NOLGTESTING
  233.  
  234. #ifdef LGTESTING
  235.  
  236.  
  237. #define LGMAXSLOTS        5
  238. #define LGMINSLOTS        ((LGMAXSLOTS - 1) / 2)
  239.  
  240. #define LGMAXLEAF        16
  241. #define LGMINLEAF        (ALIGNSIZE(LGMAXLEAF / 2))
  242.  
  243. #define LGMAXPAGESLOTS    6    
  244. #define LGMINPAGESLOTS    ((LGMAXPAGESLOTS - 1) / 2)
  245.  
  246.  
  247. #else
  248.  
  249.  
  250. #define LGMAXSLOTS        ((LG_PAGESIZE - sizeof(LGNODEHDR)) / sizeof(LGSLOT))
  251. #define LGMINSLOTS        ((LGMAXSLOTS - 1) / 2)
  252.  
  253. #define LGMAXLEAF        LGDATA_USABLESIZE
  254. #define LGMINLEAF        (ALIGNSIZE(LGMAXLEAF / 2))
  255.  
  256. #define LGMAXPAGESLOTS    24    
  257. #define LGMINPAGESLOTS    ((LGMAXPAGESLOTS - 1) / 2)
  258.  
  259.  
  260. #endif
  261.  
  262.  
  263. /*
  264.  *    "Pointer" to a version history graph node
  265.  */
  266. typedef struct VHGNODEPTR {
  267.     OID            oid;    /* object containing the version graph    */
  268.     VHGNODEID    nodeId;    /* node in the graph for this large obj    */
  269. } VHGNODEPTR;
  270.  
  271. /*
  272.  *    define the header field of a large object node
  273.  */
  274. typedef struct LGNODEHDR {
  275.  
  276.     MAGIC        magic;                    /* magic number for            */
  277.  
  278.     ONE            height;                    /* distance to leaf nodes    */
  279.     TWO            numSlots;                /* number of slots in node    */
  280.  
  281.     VHGNODEPTR    vhgPtr;                    /* Version history graph node
  282.                                            for this large object     */
  283.     /*
  284.      *    The vhgPtr field would be best be located in the large object
  285.      *    header, but this would require the minumum size of small 
  286.      *    objects to be significantly larger.  Therefore it is placed
  287.      *    here.  Only the root page header will contain a valid
  288.      *    VHGNODEPTR.
  289.      */
  290.  
  291.     LRC            lrc;                        /* lrc for node pages        */
  292.  
  293. } LGNODEHDR;
  294.  
  295.  
  296. /*
  297.  *    Internal node format (also root format for now).
  298.  */
  299. typedef struct LGNODE {
  300.  
  301.     LGNODEHDR    header;                    /* header of the node            */
  302.     LGSLOT        slot[LGMAXSLOTS];        /* array of slots themselves    */
  303.  
  304. } LGNODE;
  305.  
  306.  
  307. /*
  308.  *    define the magic number for the large object pages
  309.  */
  310. #define LARGENODE_MAGIC        0x40237819
  311.  
  312.  
  313. /*
  314.  *    Internal node format (also root format for now).
  315.  */
  316. typedef struct LGSLOTROOT {
  317.  
  318.     LGNODEHDR    header;                    /* header of the node            */
  319.     LGSLOT        slot[LGMAXPAGESLOTS];    /* array of slots themselves    */
  320.  
  321. } LGSLOTROOT;
  322.  
  323.  
  324. #define SLOTROOT_MAGIC    0x345aedf7
  325.  
  326. /*
  327.  *    Typedef for large objects with root on seperate page.
  328.  */
  329. typedef struct LARGEOBJHDR {
  330.  
  331.     OBJHDR        objectHdr;    /* the object's header                    */
  332.        SHORTPID    rootPid;    /* the page id of the object's root     */
  333.     /*
  334.      *    If fields are changed here, see the definition of 
  335.      *    SMALLOBJ so that the minumum size of a small object is
  336.      *    large enough to hold a LARGEOBJHDR.
  337.      */
  338.  
  339. #if (ALIGNON == 8)
  340.     FOUR        filler;            /* to give 8 byte alignment        */
  341. #elif (ALIGNON == 4)
  342.     /* no alignment needed */
  343. #else
  344.     not implemented
  345. #endif
  346.  
  347. } LARGEOBJHDR;
  348.  
  349.  
  350. /*
  351.  *    Typedef for large objects with root on slotted page
  352.  */
  353. typedef struct LARGEOBJROOT {
  354.  
  355.     OBJHDR            objectHdr;        /* the object's header            */
  356.     LGSLOTROOT        rootPage;        /* the root on the slotted page    */
  357.  
  358. } LARGEOBJROOT;
  359.  
  360.  
  361. /*
  362.  *    Header for large object data page
  363.  */
  364. typedef struct LGDATAHDR {
  365.  
  366.     LRC        lrc;
  367.     MAGIC    magic;
  368.  
  369. #if (ALIGNON == 8)
  370.     FOUR        filler;            /* to give 8 byte alignment        */
  371. #elif (ALIGNON == 4)
  372.     /* no alignment needed */
  373. #else
  374.     not implemented
  375. #endif
  376.  
  377. } LGDATAHDR;
  378.  
  379. #define LGDATAHDR_MAGIC        0xf111111f
  380.  
  381. /*
  382.  *    Available space for data on large object data page
  383.  */
  384. #define LGDATA_USABLESIZE    (LGDATA_PAGESIZE - sizeof(LGDATAHDR))
  385.  
  386. /*
  387.  *    large object data page
  388.  *    It is important to have the header at the end of the page so
  389.  *    that it will be overwritten when the pages are placed 
  390.  *    contiguously.
  391.  */
  392. typedef struct LGDATAPAGE {
  393.     
  394.     char        data[LGDATA_USABLESIZE];
  395.     LGDATAHDR    header;
  396.  
  397. } LGDATAPAGE;
  398.  
  399.  
  400. /* BEGIN visible to user */
  401. /*
  402.  *    Properties bits; only a few for now.
  403.  */
  404. #define P_LARGEOBJ        0x1        /* whether this is a large object        */
  405. #define P_HEADERONPAGE    0x2        /* large object header is on the page    */
  406. #define P_PAGESIZEOBJ    0x4        /* whether this is a page size object    */
  407. #define P_MOVED            0x8        /* object has been moved to a new page    */
  408. #define P_FORWARD        0x10    /* this is the forwarded record            */
  409. #define P_VERSIONED        0x20    /* object is versioned                   */
  410. #define P_FROZEN        0x40    /* object is frozen version             */
  411. #define P_HISTORYGRAPH    0x80    /* object is a version history graph */
  412. #define P_DESTROYPENDING    0x100    /* object is marked to be destroyed
  413.                                        pending freezing of all working i
  414.                                        verions */
  415. #define P_INDEX            0x200    /* object is an index                    */
  416. #define P_CREATEINPROGRESS    0x400    /* object is process of being created.
  417.                                         used for logging lg obj creates. */
  418.  
  419. /*
  420.  *    define a type for a slot that includes a unique number
  421.  */
  422. typedef struct  PAGESLOT {
  423.  
  424.     FOUR    offset;
  425.     UNIQUE    unique;
  426.  
  427. } PAGESLOT;
  428.  
  429.  
  430. /*
  431.  *    Define a header for the slotted page
  432.  */
  433. typedef struct SLOTTEDHEADER {
  434.  
  435.     SLOTINDEX      slotCount;            /* slots in use on the page                */
  436.     SLOTINDEX    freeSlot;            /* list of free slots                    */
  437.     LRC            lrc;                /* lrc for logging                        */
  438.     FOUR         freeStart;            /* offset of contig free area on page    */
  439.     FOUR         freeBytes;            /* free bytes in the page                */
  440.     PID         pid;                /* the page's pid                        */
  441.     FID         fid;                /* the file the page belongs to            */
  442.     PID         neighborPid;        /* the neighboring page Pid                */
  443.     SHORTPID    nextLogicalPid;        /* used for logical sequence sets        */
  444.     FOUR        largeCount;            /* marked if the page has large obj        */
  445.     UNIQUE        unique;                /* current unique value                    */
  446.     FOUR        uniqueCount;        /* limit of unique values                */
  447.     MAGIC        magic;
  448.  
  449. } SLOTTEDHEADER;
  450.  
  451.  
  452. /*
  453.  *    Amount of contiguous free space initially on page.
  454.  */
  455. #define INITIALLYFREE    (SLOTTED_PAGESIZE - sizeof(SLOTTEDHEADER))
  456.  
  457. /*
  458.  *    the definition of a page
  459.  */
  460. typedef struct SLOTTEDPAGE {
  461.  
  462.     char            data[INITIALLYFREE - sizeof(PAGESLOT)];    /* the data region    */
  463.     PAGESLOT        slot[1];            /* slot array, indexes backwards        */
  464.     SLOTTEDHEADER    header;                /* header of the slotted page            */
  465.  
  466. } SLOTTEDPAGE;
  467.  
  468.  
  469. #define SLOT_PAGE_MAGIC            0xb1a5dccb
  470.  
  471.  
  472. /* 
  473.  *    Maximum number of slots on a page.
  474.  */
  475. #define MAXPAGESLOTS    ((SLOTTED_PAGESIZE - sizeof(SLOTTEDHEADER)) / sizeof(PAGESLOT))
  476.  
  477.  
  478. /*
  479.  *    Define for the threshold at which a new object starts life as
  480.  *    a large object rather than a small object.  This must be defined
  481.  *    to include the size of the small object header.
  482.  */
  483. #ifdef LGTESTING
  484. #    define LARGETHRESHOLD    LGMAXLEAF
  485. #else
  486. #    define LARGETHRESHOLD    \
  487.         (SLOTTED_PAGESIZE - (sizeof(SLOTTEDHEADER) + sizeof(PAGESLOT) + sizeof(OBJHDR)))
  488. #endif
  489.  
  490.  
  491. /*
  492.  *    define the largest large object that will fit in a tree with
  493.  *    the root on a slotted page
  494.  */
  495. #define LSLOTTHRESHOLD        (LGMAXPAGESLOTS * LGMAXLEAF)
  496.  
  497.  
  498. /*
  499.  *    define some state variables for checking for free space
  500.  */
  501. #define PAGE_NO_SPACE        0x0
  502. #define PAGE_LAST_SLOT        0x1
  503. #define PAGE_INT_SLOT        0x2
  504.  
  505.  
  506. /*
  507.  *    define the hash function for hashing an oid
  508.  */
  509. #define BF_HashOid(_oid)                                \
  510.     ((_oid)->diskAddr.unique & ObjectHashMask)
  511.  
  512.  
  513.  
  514. #define INIT_LARGENODE_MAGIC(_nodePtr)                    \
  515.                                                         \
  516.     (_nodePtr)->header.magic = LARGENODE_MAGIC;            
  517.     
  518. #define INIT_LGDATAHDR_MAGIC(_nodePtr)                    \
  519.                                                         \
  520.     (_nodePtr)->header.magic = LGDATAHDR_MAGIC;            
  521.     
  522. #define INIT_SLOTROOT_MAGIC(_nodePtr)                    \
  523.                                                         \
  524.     (_nodePtr)->header.magic = SLOTROOT_MAGIC;            
  525.  
  526.     
  527. /*
  528.  *    define a check for a large node magic number
  529.  */
  530. #define CHECK_LARGENODE_MAGIC(_nodePtr)                    \
  531.                                                         \
  532.     if ((_nodePtr)->header.magic != LARGENODE_MAGIC)    {    \
  533.         SM_ERROR(TYPE_FATAL, esmINTERNAL);                \
  534.     }
  535.     
  536.  
  537. /*
  538.  *    define a check for a large data magic number
  539.  */
  540. #define CHECK_LGDATAHDR_MAGIC(_nodePtr)                    \
  541.                                                         \
  542.     if ((_nodePtr)->header.magic != LGDATAHDR_MAGIC)    {    \
  543.         SM_ERROR(TYPE_FATAL, esmINTERNAL);                \
  544.     }
  545.     
  546.  
  547. /*
  548.  *    define a check for a large node magic number
  549.  */
  550. #define CHECK_SLOTROOT_MAGIC(_nodePtr)                    \
  551.                                                         \
  552.     if ((_nodePtr)->header.magic != SLOTROOT_MAGIC)    {    \
  553.         SM_ERROR(TYPE_FATAL, esmINTERNAL);                \
  554.     }
  555.  
  556.  
  557. /*
  558.  *    define index descriptor stuff
  559.  */
  560.  
  561. #define SM_MAXELEMLEN   20      /* range 4--124 (multiples of 4) */
  562.  
  563. typedef enum { SM_BTREENDX, SM_HASHNDX } SMTYPE;
  564.  
  565. typedef enum { SM_EQ = 1, SM_G = 2, SM_L = 4,
  566.                 SM_GEQ = 3, SM_LEQ = 5 } SMCOND;
  567.  
  568. #define SM_BOF    NULL, SM_GEQ
  569. #define SM_EOF    NULL, SM_LEQ
  570.  
  571. typedef enum { SM_char, SM_int, SM_long, SM_short, SM_float, 
  572.                 SM_double, SM_string } SMDATATYPE;
  573. #define SM_Boolean SM_char
  574.  
  575. /* END visible to user */
  576.  
  577.  
  578.  
  579. #define NDXMAGIC     0x140267
  580. typedef struct INDEXDESC {
  581.         SMTYPE        ndxType;        /* index type */
  582.         PID            rootPid;        /* root page ID */
  583.         TWO            maxKeyLen;        /* maximum length of key */
  584.         TWO            elSize;
  585.         SMDATATYPE    dataType;
  586.         ONE            unique;            /* TRUE if index is unique */
  587. } INDEXDESC;
  588.         
  589. typedef struct INDEXDESCPAGE {
  590.         FOUR        magic;
  591.         LRC            lrc;
  592.         INDEXDESC    desc;
  593. } INDEXDESCPAGE;
  594.         
  595.  
  596. /* BEGIN visible to user */
  597.  
  598. typedef struct IID {
  599.         PID     pid;
  600. } IID;                    /* INDEX IDENTIFIER */
  601.  
  602. #ifdef __cplusplus
  603. #ifdef PIDEQ
  604. inline operator ==(const IID& i1, const IID& i2) {
  605.         return PIDEQ(i1.pid, i2.pid);
  606.         }
  607. inline operator !=(const IID& i1, const IID& i2) {
  608.         return ! (i1 == i2);
  609.         }
  610. #endif PIDEQ
  611. #endif __cplusplus
  612.  
  613. #define PFCDEFINED
  614. #ifdef __cplusplus
  615. typedef int     (*PFC) PROTO((int kLen1, const void* kVal1, 
  616.                                     int kLen2, const void* kVal2));
  617. #else
  618. typedef int     (*PFC) PROTO((int kLen1, void* kVal1, int kLen2, void* kVal2));
  619. #endif
  620.  
  621. typedef void    (*PFK) PROTO((int kLen, char* kVal));
  622.  
  623.  
  624. /* END visible to user */
  625.  
  626. extern PFC SMCOMPFUNC [ SM_string + 1];
  627.  
  628.  
  629. #endif __OBJECT_H__
  630. #endif /* _OBJECT_H_ */
  631.